package com.girlcoding.jianfei.activities;
import com.girlcoding.jianfei.util.ToastUtil;
import com.girlcoding.jianfei.widget.FlipActivityWidget;
import com.girlcoding.jianfei.widget.IFlipActivityListener;
import com.girlcoding.www.R;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;

/**
 * @author Tinker
 * @createDate 2011-6-20
 * @version v0.1
 */
public class HomeActivity extends ActivityGroup implements IFlipActivityListener{
	private FlipActivityWidget mContainer;
	private LocalActivityManager mActivityManager;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initUI();
	}

	private void initUI() {
		setContentView(R.layout.activity_group_home);
		mContainer = (FlipActivityWidget) findViewById(R.id.container);
		mActivityManager = getLocalActivityManager();
		
		addViewByClass(BaseFoodActivity.class);
		addViewByClass(BaseSportsActivity.class);
		addViewByClass(BaseInteractiveActivity.class);
		addViewByClass(BaseSettingsActivity.class);
		
		mContainer.addListener(this);
	}

	public void barSelectHandler(View view) {
		if (!(view instanceof RadioButton))
			return;
		switch (view.getId()) {
		case R.id.bar_type_food:
			mContainer.snapToScreen(0);
			break;
		case R.id.bar_type_sports:
			mContainer.snapToScreen(1);
			break;
		case R.id.bar_type_interactive:
			mContainer.snapToScreen(2);
			break;
		case R.id.bar_type_settings:
			mContainer.snapToScreen(3);
			break;
		default:
			break;
		}
	}
	
	public void addViewByClass(Class<?> cls) {
		Intent intent = new Intent(HomeActivity.this, cls);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		View decodeView = mActivityManager.startActivity(cls.getSimpleName(),
				intent).getDecorView();
		mContainer.addView(decodeView);
	}

	@Override
	public void onFlipCompleted() {
		ToastUtil.ToastShort(getBaseContext(), "onFlipCompleted");
	}

	@Override
	public void onFlipStarted() {
		ToastUtil.ToastShort(getBaseContext(), "onFlipStarted");
	}

	@Override
	public void onNotFlip() {
		ToastUtil.ToastShort(getBaseContext(), "onNotFlip");
	}
}
